/*
 * Created on Dec 7, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.jds.apps.hr.skill.category.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.jds.apps.hr.skill.category.form.ext.AbstractCategoryForm;
import com.jds.architecture.utilities.ObjectIsNull;
import com.jds.architecture.utilities.StringIsEmpty;
import com.jds.architecture.utilities.StringIsValid;
import com.jds.architecture.utilities.StringLengthIsValid;
import com.jds.architecture.utilities.Validator;



/**
 * 
 *
 * @author ma.j.a.valiente
 * @author last modified by: $Author: c.b.balajadia ${date}
 * @version $Revision: 1.4 $ $Date: 2005/03/17 08:08:18 $
 * 
 */
public class CategoryForm extends AbstractCategoryForm {

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {

        
		
		
  
       //TODO: Implement validation
		String category = getCategory(); 
		
		Validator objcetIsnull = new Validator(new ObjectIsNull());
		Validator stringIsEmpty = new Validator(new StringIsEmpty());
		Validator stringIsValid = new Validator(new StringIsValid(""));
		Validator stringLengthIsValid = new Validator(new StringLengthIsValid(50));

		Validator objcetIsnull1 = new Validator(new ObjectIsNull());
		Validator stringIsEmpty1 = new Validator(new StringIsEmpty());
		Validator stringIsValid1 = new Validator(new StringIsValid(" "));
		Validator stringLengthIsValid1 = new Validator(new StringLengthIsValid(100));
		
		String description = getDescription();
		
		ActionErrors errors = new ActionErrors();
		
		if (objcetIsnull.validate(category))
        {
        	errors.add("category", new ActionError("field.null","Category"));
        }
		if (stringIsEmpty.validate(category))
        {
        	errors.add("category", new ActionError("field.null","Category"));
        }

		if (!stringIsValid.validate(category))
        {
        	errors.add("category", new ActionError("field.invalid.specialcharacter","Category"));
        }
        if (!stringLengthIsValid.validate(category))
        {
        	errors.add("category", new ActionError("field.invalid.length","Category"));
        }
        
        //Description
        
        if (objcetIsnull1.validate(description))
        {
        	errors.add("description", new ActionError("field.null","Description"));
        }
    	if (stringIsEmpty1.validate(description))
        {
        	errors.add("description", new ActionError("field.null","Description"));
        }

        if (!stringIsValid1.validate(description))
        {
        	errors.add("description", new ActionError("field.invalid.specialcharacter","Description"));
        }
        if (!stringLengthIsValid1.validate(description))
        {
        	errors.add("description", new ActionError("field.invalid.length","Description"));
        }
        
		return errors;
	}
	
}
